#!/bin/bash
TOMCATPATH=/home/app/tomcat-6.0.29-remote
. /etc/profile
. ~/.bashrc
. ~/.bash_profile

pid=`ps aux | grep tomcat | grep $TOMCATPATH | grep -v grep | awk '{print $2}'`
echo $pid
if [ -n "$pid" ]; then
	echo "==========stop tomcat============">>/home/tom_reboot.log
	${TOMCATPATH}/bin/shutdown.sh
	echo "==========start sleep 10============">>/home/tom_reboot.log
	sleep 10
	pid=`ps aux | grep tomcat | grep $TOMCATPATH | grep -v grep | awk '{print $2}'`
	if [ -n "$pid" ]; then
		echo "======to kill the tomcat pid $pid========">>/home/tom_reboot.log
		kill -9 $pid
		sleep 3
	fi
	
	echo "==========start tomcat again============">>/home/tom_reboot.log
	${TOMCATPATH}/bin/startup.sh

else
	echo "===============start tomcat=============">>/home/tom_reboot.log
	${TOMCATPATH}/bin/startup.sh
fi

exit
